package com.education.web.utils;

import com.education.web.dto.SystemSecurityUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author zengjintao
 * @version 1.0
 * @create_at 2019/12/28 14:03
 */
public class UserUtils {

    /**
     * 获取用户信息
     * @return
     */
    public static SystemSecurityUser getSystemSecurityUser() {
         Authentication authentication = SecurityContextHolder.getContext()
                .getAuthentication();
        if (authentication.getPrincipal() instanceof SystemSecurityUser) {
            return (SystemSecurityUser) authentication.getPrincipal();
        }
        return null;
    }

    public static Authentication getAuthentication() {
        Authentication authentication = SecurityContextHolder.getContext()
                .getAuthentication();
        return authentication;
    }

}
